import string
class CDataString:
    '''In log files the data message is displayed as string format'''

    _gByteCnt=2 #every byte of message data use 2 bytes in string

    def __init__(self, dataStr):
        self._rawStr = dataStr.upper()
        self._dataIndex = 0

    def Reset(self):
        self._dataIndex = 0

    def SetIndex(self, index):
        self._dataIndex = index * self._gByteCnt

    def GetIndex(self):
        return self._dataIndex / self._gByteCnt

    def Show(self, start, end):
        print self._rawStr[start * CDataString._gByteCnt : end * CDataString._gByteCnt]

    def GetString(self, start, end):
        return self._rawStr[start * CDataString._gByteCnt : end * CDataString._gByteCnt]
    def GetRawString(self):
        return self._rawStr

    def GetByte(self):
        '''Get byte value of the data message using current index'''
        temp = self._rawStr[self._dataIndex : (self._dataIndex+self._gByteCnt)]
        self._dataIndex = self._dataIndex + self._gByteCnt
        if temp != '':
            value=string.atoi(temp, 16)
        else:
            value = 0
        return value

if __name__ == "__main__":
    data = CDataString("12345")
    print data.GetByte()
    print data.GetByte()
    print data.GetByte()

